package com.intertid.szjk.Ws;

import java.io.File;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;


public class Randomizer extends Random {

	private static final long serialVersionUID = -1L;

	public static Randomizer getInstance() {
		return _instance;
	}

	public Randomizer() {
		super();
	}

	public Randomizer(long seed) {
		super(seed);
	}

	public int[] nextInt(int n, int size) {
		if (size > n) {
			size = n;
		}

		Set<Integer> set = new LinkedHashSet<Integer>();

		for (int i = 0; i < size; i++) {
			while (true) {
				Integer value = new Integer(nextInt(n));

				if (!set.contains(value)) {
					set.add(value);

					break;
				}
			}
		}

		int[] array = new int[set.size()];

		Iterator<Integer> itr = set.iterator();

		for (int i = 0; i < array.length; i++) {
			array[i] = itr.next().intValue();
		}

		return array;
	}

	public void randomize(char array[]) {
		int length = array.length;

		for (int i = 0; i < length - 1; i++) {
			int x = nextInt(length);
			char y = array[i];

			array[i] = array[i + x];
			array[i + x] = y;

			length--;
		}
	}

	public void randomize(int array[]) {
		int length = array.length;

		for (int i = 0; i < length - 1; i++) {
			int x = nextInt(length);
			int y = array[i];

			array[i] = array[i + x];
			array[i + x] = y;

			length--;
		}
	}

	public void randomize(List<Object> list) {
		int size = list.size();

		for (int i = 0; i <= size; i++) {
			Object obj = list.get(i);

			int j = nextInt(size);

			list.set(i, list.get(i + j));
			list.set(i + j, obj);

			size--;
		}
	}

	public void randomize(Object array[]) {
		int length = array.length;

		for (int i = 0; i < length - 1; i++) {
			int x = nextInt(length);
			Object y = array[i];

			array[i] = array[i + x];
			array[i + x] = y;

			length--;
		}
	}

	public String randomize(String s) {
		if (s == null) {
			return null;
		}

		char[] array = s.toCharArray();

		randomize(array);

		return new String(array);
	}

	public String getFixLenthString(int strLength) {

		Random rm = new Random();

		// 获得随机数  
		double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);

		// 将获得的获得随机数转化为字符串  
		String fixLenthString = String.valueOf(pross);

		// 返回固定的长度的随机数  
		return fixLenthString.substring(1, strLength + 1);
	}

	private static Randomizer _instance = new Randomizer();

	public static void main(String[] args) {
		for (int a = 0; a < 10; a++) {
			String appendixPath = "";
			String day = DateUtil.toString(new Date(), "dd");
			String yearAndMonth = DateUtil.toString(new Date(), "yyyyMM");
			String currDateTime = DateUtil.toString(new Date(), "yyyyMMddHHmmss");
			String randomNum = String.valueOf(Randomizer.getInstance().nextInt(100000000, 1)[0]);
			System.err.println(randomNum.length());
			if (randomNum.length() < 8) {
				for (int i = 0; i < 8 - randomNum.length(); i++) {
					randomNum += "0";
				}
			}
			System.err.println(randomNum);
			appendixPath = "e:\\ecm\\uploadfiles" + File.separator + yearAndMonth + File.separator + day + File.separator + currDateTime + randomNum + ".jpg";
			System.err.println(currDateTime);
			System.err.println(appendixPath);
			System.err.println(appendixPath.substring(appendixPath.lastIndexOf(File.separator) + 1));
			System.err.println(appendixPath.substring(appendixPath.lastIndexOf(".") + 1));
			System.err.println(appendixPath.substring(appendixPath.indexOf("\\uploadfiles")));
			System.err.println("==============================");
		}
	}

}